import axios from 'axios';
import Vue from 'vue';
import Vuex from 'vuex';
import city from './city'
Vue.use(Vuex);

const store = new Vuex.Store({
    modules:{
        city
    },
    state:{
         wdll:'退出',
        isLogin:false
    },
mutations:{
    changeIsLogin(state,payload){
        state.isLogin = payload;
    }   
},
actions:{
    async Login(store,payload){
        //console.log(payload)//{un:xxx,pw:xxx}
         let res = await axios.post('/qf/users/regist',{
              username:payload.un,
              password:payload.pw,
            
         })
         if(res.code===0){
            store.commit('changeIsLogin',true)
        }else{
            store.commit('changeIsLogin',false)
        }
         
    },
    
    // 异步修改state里面的内容
    async asyncLogin(store,payload){
    console.log(payload)//{un:xxx,pw:xxx}
    let res = await axios.post('/qf/users/login',{
         username:payload.un,
         password:payload.pw,
        
     });
     console.log(res)
    if(res.code===0){
        store.commit('changeIsLogin',true)
    }else{
        store.commit('changeIsLogin',false)
    }
    }
}

})



export default store;